/**
 * zhoushengtao 
 * 2012-08-24 14:27:56
 */
package com.stchou.superbrowser.ui.widget;

import com.stchou.superbrowser.activity.R;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

public class SuperConfirmDialog extends Dialog
{

    private TextView mTitle;
    private TextView mTextBody;
    private Button mLeftButton;
    private Button mRightButton;
    private ImageButton mCloseButton;

    public static class Builder
    {
        private SuperConfirmDialog mDialog;

        public Builder(Context context)
        {
            mDialog = new SuperConfirmDialog(context, R.style.SuperDialogTheme);
        }

        public Builder setTitle(String title)
        {
            mDialog.mTitle.setText(title);
            return this;
        }

        public Builder setMessage(String title)
        {
            mDialog.mTextBody.setText(title);
            return this;
        }

        public Builder setLeftButtonListener(
                android.view.View.OnClickListener listener)
        {
            mDialog.mLeftButton.setOnClickListener(listener);
            return this;
        }

        public Builder setRightButtonListener(
                android.view.View.OnClickListener listener)
        {
            mDialog.mRightButton.setOnClickListener(listener);
            return this;
        }

        public Builder setCloseButtonListener(
                android.view.View.OnClickListener listener)
        {
            mDialog.mCloseButton.setOnClickListener(listener);
            return this;
        }

        public Builder setLeftButtonBackground(int resid)
        {
            mDialog.mLeftButton.setBackgroundResource(resid);
            return this;
        }

        public Builder setRightButtonBackground(int resid)
        {
            mDialog.mRightButton.setBackgroundResource(resid);
            return this;
        }

        public Builder setCloseButtonBackground(int resid)
        {
            mDialog.mCloseButton.setBackgroundResource(resid);
            return this;
        }

        public Builder setLeftButtonText(String string)
        {
            mDialog.mLeftButton.setText(string);
            return this;
        }
        
        public Builder setRightButtonText(String string)
        {
            mDialog.mRightButton.setText(string);
            return this;
        }

        public SuperConfirmDialog show()
        {
            mDialog.show();
            return mDialog;
        }

        public void dismiss()
        {
            mDialog.dismiss();
        }

    }

    public SuperConfirmDialog(Context context)
    {
        super(context);
    }

    public SuperConfirmDialog(Context context, int theme)
    {
        super(context, theme);
        setContentView(R.layout.dialog_alert);
        mTitle = (TextView)findViewById(R.id.title);
        mTextBody = (TextView)findViewById(R.id.text_body);
        mLeftButton = (Button)findViewById(R.id.left_button);
        mRightButton = (Button)findViewById(R.id.right_button);
        mCloseButton = (ImageButton)findViewById(R.id.close);
        mCloseButton
                .setOnClickListener(new android.view.View.OnClickListener()
                {

                    public void onClick(View v)
                    {
                        dismiss();

                    }
                });
    }

    public void setTitle(String title)
    {
        mTitle.setText(title);
    }

    public void setMessage(String title)
    {
        mTextBody.setText(title);
    }

    public void setLeftButtonListener(android.view.View.OnClickListener listener)
    {
        mLeftButton.setOnClickListener(listener);
    }

    public void setRightButtonListener(android.view.View.OnClickListener listener)
    {
        mRightButton.setOnClickListener(listener);
    }
    
    public void setCloseButtonListener(
            android.view.View.OnClickListener listener)
    {
        mCloseButton.setOnClickListener(listener);
    }

    public void setLeftButtonBackground(int resid)
    {
        mLeftButton.setBackgroundResource(resid);
    }

    public void setRightButtonBackground(int resid)
    {
        mRightButton.setBackgroundResource(resid);
    }
    
    public void setCloseButtonBackground(int resid)
    {
        mCloseButton.setBackgroundResource(resid);
    }

}
